<template>
	<view class="list" >
		<scroll-view class="list-c" scroll-y="true" :scroll-top="scrollTop" @scrolltolower="scrolltolower" lower-threshold="50">
			<view class="items">
				<view class="item" v-for="(item,index) in list" :key='index'>
					<view class="imgBox" :style="{ backgroundImage: `url(${item.file_list[0].file_key})`}">
						
					</view>
					<view class="info">
						<view class="title ellipsis">{{item.title}}</view>
						<view class="n-title ellipsis">著者: {{item.auther}}</view>
						<view class="n-title ellipsis">出版社: {{item.company}}</view>
						<view class="n-title ellipsis">分类: {{item.category}}</view>
						<view class="n-ps">票数: <text class="red">{{item.total_vote}}</text></view>
					</view>
					<view class="btn" @tap="eventTp(item)" v-show="item.is_vote_btn == 1">投票</view>
					<view class="btn disable" v-show="item.is_vote_btn !=1">投票</view>
					<view class="btn" v-show="item.today_already_vote > 0">已投票</view>
					<view class="num">No.{{item.id}}</view>
				</view>
			</view>
		</scroll-view>
		<view class="bottom">
			今天剩余投票数: <text class="red">{{vote_remainder_num}}</text>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				 scrollTop: 0,
				 old: {
					 scrollTop: 0
				 },
				list:[],
				is_bottom:false,
				total:0,
				totlePage:1,
				page:1,
				
				vote_remainder_num:0
			}
		},
		onLoad:function(option){
			  // this.currentNav = option.index;
			  // this.node_id = option.node_id;
			  this.render();
		},
		onShow: function(){
			
		},
		computed:{
			
		},
		methods: {
			async eventTp(item) {
				const res = await this.$http({
					url:'/api/activity/vote/' + item.id,
					method:"post",
					data:{}
				})
				if(res) {
					uni.showToast({
						title:'投票成功',
					    icon:'none'
					})
					// console.log(res.data);
					this.vote_remainder_num = res.data.residue_num;
					item.today_already_vote = 1;
					item.total_vote ++;
					console.log(this.vote_remainder_num);
				}
				// console.log(res);
			},
			async render(){
				const _this = this;
				if (this.page > this.totlePage) {
					this.is_bottom = true;
				}else{
					const _this = this;
					const res = await this.$http({
						url:'/api/activity/1',
						method:"get",
						data:{
							page:_this.page,
							page_count:10
						}
					})
					console.log(res.data.data);
					// this.list = res.data.data.data;
					this.total = res.data.data.total_page;
					this.totlePage = res.data.data.total_page;
					this.list.push(...res.data.data.data);
					this.vote_remainder_num = res.data.data.vote_remainder_num;
					
					this.page ++;
				}
			},
			scrolltolower(){
				this.render();
			}
		}
	}
</script>

<style lang="scss">
	.ellipsis {
	  white-space: nowrap; /* 确保文本在一行内显示 */
	  overflow: hidden; /* 隐藏溢出的内容 */
	  text-overflow: ellipsis; /* 使用省略号表示文本溢出 */
	}
    .list {
		 // display:flex;
		 // justify-content: space-between;
		 // padding-right: 32rpx;
		 height: 100%;
		 .list-c{
			  width:100%;
			  height: 100%;
			  overflow: hidden;
			  background-color: #f6f6f6;
			  .items {
				  padding: 20rpx 35rpx 150rpx 35rpx;
			  }
			  .item {
				  display: flex;
				  background-color: #fff;
				  padding: 30rpx 40rpx;
				  position: relative;
				  .num {
					  position: absolute;
					  right: 20rpx;
					  top:5rpx;
					  font-size: 27rpx;
				  }
				  .btn {
					  position: absolute;
					  color:#fff;
					  background-color: #dc3d33;
					  border: none;
					  right: 25rpx;
					  bottom: 20rpx;
					  width: 168rpx;
					  height: 62rpx;
					  border-radius: 10rpx;
					  @include center();
					  &.disable {
						  border: none;
						  background-color: #d1d1d1;
						  color:#fff;
					  }
				  }
				  .info {
					  padding-top: 15rpx;
				  }
				  .title {
					  font-weight: bold;
					  font-size: 36rpx;
					  margin-bottom: 20rpx;
					  width: 350rpx;
				  }
				  .n-title {
					 font-size: 26rpx;
					 color:#5e5e5e;
					  width: 350rpx;
				  }
				  .n-ps {
					  padding-top: 20rpx;
				  }
				  .red {
					  color:#d12626;
					  
				  }
			  }
			  .imgBox {
				  width: 203rpx;
				  height: 260rpx;
				  margin-right: 25rpx;
			  }
		 }
		 
		 ::-webkit-scrollbar {
		   width: 0;
		   height: 0;
		   color: transparent;
		 }
		 
		 .pdf-lou {
			 background-color: #fff;
			 border-radius: 18rpx;
			 padding: 36rpx 36rpx;
			 margin-top: 32rpx;
			 color:#2e323e;
			 overflow: hidden; 
			 text-overflow: ellipsis;
			 white-space: nowrap;
			 
		 }
		
		 .is_bottom{
			 height: 75rpx;
			 line-height: 75rpx;
		 }
		

			.vidoe-lou {
				padding-top: 32rpx;
				margin-bottom:32rpx;
				.videoWrap {
					width: 100%;
					height: 280rpx;
					margin-bottom: 22rpx;
					position: relative;
					border-radius: 8rpx;
					overflow: hidden;
					.videoIcon {
						width: 50rpx;
						height:33rpx;
						position: absolute;
						top:30rpx;
						left:20rpx;
					}
					image {
						width: 100%;
						height: 280rpx;
					}
				}
				.name {
					color: #2e323e;
					max-height: 80rpx;
					overflow: hidden;
					margin-bottom: 10rpx;
				}
				.time {
					color: #868c9f;
					height: 52rpx;
					line-height: 52rpx;
					
				}
			}
	
		
		
	  .title-lou {
	  			 padding: 34rpx;
	  			 background-color: #fff;
	  			
	  			 margin-top: 28rpx;
	  			 .name {
	  			 	 font-size: 32rpx;
	  			 }
	  			 
	  			 .bts {
	  				 display: flex;
	  				 justify-content: space-between;
	  				 padding-top: 24rpx;
	  				 .tagBt {
	  					 position:relative;
	  					 top:-14rpx;
	  					 color:#cccccc;
	  				 }
	  				 .bt {
	  					 width: 134rpx;
	  					 height: 56rpx;
	  					 border-radius: 28rpx;
	  					 color:#fff;
	  					 @include  center;
	  					 font-size: 24rpx;
	  				 }
	  			 }
	  			
	  }
	}
	.bottom {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 130rpx;
		background-color: #fff;
		@include center();
		font-size: 36rpx;
		.red {
			color:#dc3e33;
		}
	}
	
</style>

